home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / hotspots / reqfiles / rollover.sx < prev   
Encoding:
Text File  |  1996-05-21  |  5.4 KB  |  170 lines  |  [TEXT/ttxt]

  1. in module DemoModule
  2.  
  3. --*******************************************************************************
  4. --*        Class name:    Rollover
  5. --*                                            
  6. --*     Inherits from: RootObject                                    
  7. --*        Class type: Abstract, mixin
  8. --*         Component: User Interface
  9. --*
  10. --*       Description: This class provides the basic protocols for rollover 
  11. --*                    functionality to any TwoDShape.
  12. --*                    
  13. --*                    This class can also be combined with a Button class to 
  14. --*                    give you a Rollover Button.
  15. --*
  16. --*             Usage: Create a new multi-inherited class
  17. --*                        class myRollover (TwoDShape, Rollover)
  18. --*
  19. --*               IVs:    enterBitmap
  20. --*                    exitBitmap
  21. --*                    authordata
  22. --*                    enterAction
  23. --*                    exitAction
  24. --*                    rolloverInterest
  25. --*                    enabled            
  26. --*
  27. --*           Methods:    setEnterAppearance
  28. --*                    setExitAppearance
  29. --*                    mouseCross
  30. --*                    init
  31. --*                    afterInit
  32. --*                    afterLoading
  33. --*                    
  34. --*    Required files:    none
  35. --*                    
  36. --*             Notes: If mixed with Button or Actuator, list Rollover class 
  37. --*                    after them i.e. class RolloverButton (Button, Rollover)
  38. --*                    This is to ensure that when the enabled IV is set, the 
  39. --*                    button changes its appearance to its disabled state.
  40. --*
  41. --*            Author:    Su Quek - Kaleida Labs, Inc.
  42. --*******************************************************************************
  43. class Rollover (RootObject)
  44. inst vars
  45.     enterBitmap
  46.     exitBitmap
  47.     authordata
  48.     enterAction
  49.     exitAction
  50.     rolloverInterest
  51.     enabled        : true
  52. end
  53.  
  54. --*=============================================================================*
  55. --*       Method name:    setExitAppearance
  56. --*             Class:    Rollover
  57. --*             Usage: setExitAppearance self
  58. --*-----------------------------------------------------------------------------*
  59. --*       Description: Change the appearance of the shape to how it will appear
  60. --*                    when the mouse enter's the shape's boundary.
  61. --*=============================================================================*
  62. method setEnterAppearance self {class Rollover} ->
  63. (
  64.     if (self.enterBitmap != undefined) do
  65.         self.boundary := self.enterBitmap
  66. )
  67.  
  68. --*=============================================================================*
  69. --*       Method name:    setExitAppearance
  70. --*             Class:    Rollover
  71. --*             Usage: setExitAppearance self
  72. --*-----------------------------------------------------------------------------*
  73. --*       Description: Change the appearance of the shape to how it will appear
  74. --*                    when the mouse leaves's the shape's boundary.
  75. --*=============================================================================*
  76. method setExitAppearance self {class Rollover} ->
  77. (
  78.     if (self.exitBitmap != undefined) do
  79.         self.boundary := self.exitBitmap
  80. )
  81.  
  82. --*=============================================================================*
  83. --*       Method name:    mouseCross
  84. --*             Class:    Rollover
  85. --*             Usage: mouseCross self interest event
  86. --*-----------------------------------------------------------------------------*
  87. --*       Description: Displays and executes the appropriate bitmaps and actions 
  88. --*                    when the mouse enters or leaves the shape's boundary
  89. --*=============================================================================*
  90. method mouseCross self {class Rollover} interest event ->
  91. (
  92.     if not self.enabled do 
  93.         return
  94.  
  95.     if event.crossingType = @enter then
  96.     (
  97.         setEnterAppearance self
  98.         
  99.         if (self.enterAction != undefined) do
  100.             self.enterAction self.authordata
  101.     )
  102.     else
  103.     (
  104.         setExitAppearance self
  105.         
  106.         if (self.exitAction != undefined) do
  107.             self.exitAction self.authordata
  108.     )
  109. )
  110.  
  111. --*=============================================================================*
  112. --*       Method name:    init
  113. --*             Class:    Rollover
  114. --*             Usage: init self 
  115. --*-----------------------------------------------------------------------------*
  116. --*       Description: Initializes its IVs
  117. --*=============================================================================*
  118. method init self {class Rollover} #rest args 
  119.                                   #key enterBitmap:(undefined) \
  120.                                      exitBitmap:(undefined) ->
  121. (
  122.     apply nextmethod self args
  123.     self.exitBitmap := exitBitmap
  124.     self.enterBitmap := enterBitmap
  125.  
  126.     self
  127. )
  128.  
  129.                                        
  130. --*=============================================================================*
  131. --*       Method name:    afterInit
  132. --*             Class:    Rollover
  133. --*             Usage: afterInit self 
  134. --*-----------------------------------------------------------------------------*
  135. --*       Description: Sets up its appearance and mouse crossing event.
  136. --*=============================================================================*
  137. method afterInit self {class Rollover} #rest args ->
  138. (
  139.     nextmethod self
  140.     setExitAppearance self
  141.  
  142.     --*=========================================================================*
  143.     --* Create mouse events.
  144.     --*=========================================================================*
  145.     local rolloverInterest
  146.     rolloverInterest := new MouseCrossingEvent
  147.     rolloverInterest.eventReceiver := mouseCross
  148.     rolloverInterest.authorData := self
  149.     rolloverInterest.device := new MouseDevice
  150.     rolloverInterest.presenter := self
  151.     addEventInterest rolloverInterest
  152.     
  153.     self.rolloverInterest := rolloverInterest
  154.  
  155.     self
  156. )
  157.  
  158. --*=============================================================================*
  159. --*       Method name:    afterLoading
  160. --*             Class:    Rollover
  161. --*             Usage: afterLoading self str
  162. --*-----------------------------------------------------------------------------*
  163. --*       Description: Load the mouse crossing event.
  164. --*=============================================================================*
  165. method afterLoading self {class Rollover} str ->
  166. (
  167.     nextmethod self str
  168.     load self.rolloverInterest
  169. )
  170.